<?php

/**
 * @Project NUKEVIET 3.x - GETNEWS
 * @Author ĐẶNG ĐÌNH TỨ (dlinhvan@gmail.com)
 * @Copyright (C) 2010 webdep24.com All rights reserved
 * @Createdate 10/08/2012 08:00
 */

if( ! defined( 'NV_IS_FILE_ADMIN' ) ) die( 'Stop!!!' );
$page_title = "Cấu Hình Nâng Cao Module ";
$do = $nv_Request->get_int( 'do', 'post', 0 );
$active = $nv_Request->get_int( 'active', 'post', 0 );
$load_image = $nv_Request->get_int( 'load_image', 'post', 0 );
$module = $nv_Request->get_string( 'module', 'post', "" );
$width = $nv_Request->get_string( 'width', 'post', "" );
$height = $nv_Request->get_string( 'height', 'post', "" );
$image_body = $nv_Request->get_int( 'image_body', 'post', 0 );
$imgposition = $nv_Request->get_int( 'imgposition', 'post', 0 );
$bodyimg = $nv_Request->get_int( 'bodyimg', 'post', 0 );

if( ! empty( $do ) )
{
	$array_config = array();
	$array_config['active'] = $nv_Request->get_int( 'active', 'post', 0 );
	$array_config['load_image'] = $nv_Request->get_int( 'load_image', 'post', 0 );
	$array_config['module'] = $nv_Request->get_string( 'module', 'post', "" );
	$array_config['width'] = $nv_Request->get_string( 'width', 'post', "" );
	$array_config['height'] = $nv_Request->get_string( 'height', 'post', "" );
	$array_config['image_body'] = $nv_Request->get_int( 'image_body', 'post', 0 );
	$array_config['imgposition'] = $nv_Request->get_int( 'imgposition', 'post', 0 );
	$array_config['bodyimg'] = $nv_Request->get_int( 'bodyimg', 'post', 0 );
	foreach( $array_config as $config_name => $config_value )
	{
		$db->sql_query( "REPLACE INTO `" . NV_CONFIG_GLOBALTABLE . "` (`lang`, `module`, `config_name`, `config_value`) VALUES('" . NV_LANG_DATA . "', " . $db->dbescape( $module_name ) . ", " . $db->dbescape( $config_name ) . ", " . $db->dbescape( $config_value ) . ")" );
	}
	$db->sql_freeresult();
	nv_del_moduleCache( 'settings' );
	nv_del_moduleCache( $module_name );
	Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=" . $op . "&rand=" . nv_genpass() );
	die();
}
require_once ( NV_ROOTDIR . "/language/" . NV_LANG_DATA . "/admin_settings.php" );
$query = "SELECT * FROM `" . NV_CRONJOBS_GLOBALTABLE . "` WHERE run_file LIKE '%dangdinhtu%' ORDER BY `is_sys` DESC";
$result = $db->sql_query( $query );
$numrows = $db->sql_numrows( $result );
$contents = array();
while( $row = $db->sql_fetchrow( $result ) )
{
	$contents[$row['id']]['caption'] = isset( $row[NV_LANG_INTERFACE . '_cron_name'] ) ? $row[NV_LANG_INTERFACE . '_cron_name'] : ( isset( $row[NV_LANG_DATA . '_cron_name'] ) ? $row[NV_LANG_DATA . '_cron_name'] : $row['run_func'] );
	$contents[$row['id']]['edit'] = array(
		( empty( $row['is_sys'] ) ? 1 : 0 ),
		$lang_global['edit'],
		NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=add&amp;id=" . $row['id'] );
	$contents[$row['id']]['delete'] = array( ( empty( $row['is_sys'] ) ? 1 : 0 ), $lang_global['delete'] );
	$contents[$row['id']]['disable'] = array(
		( ( empty( $row['is_sys'] ) or empty( $row['act'] ) ) ? 1 : 0 ),
		( $row['act'] ? $lang_global['disable'] : $lang_global['activate'] ),
		NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=act&amp;id=" . $row['id'] );
	$contents[$row['id']]['detail'][$lang_module['interval']] = nv_convertfromSec( $row['interval'] * 60 );
	$contents[$row['id']]['detail'][$lang_module['act']] = ! empty( $row['act'] ) ? $lang_module['act1'] : $lang_module['act0'];
	$contents[$row['id']]['detail'][$lang_module['last_time']] = ! empty( $row['last_time'] ) ? nv_date( "l, d/m/Y H:i", $row['last_time'] ) : $lang_module['last_time0'];
	$contents[$row['id']]['detail'][$lang_module['last_result']] = empty( $row['last_time'] ) ? $lang_module['last_result_empty'] : $lang_module['last_result' . $row['last_result']];
	$interval = $row['interval'] * 60;
	if( empty( $row['act'] ) )
	{
		$next_time = "n/a";
	}
	else
	{
		if( empty( $interval ) )
		{
			$next_time = nv_date( "l, d/m/Y H:i", max( $row['start_time'], NV_CURRENTTIME ) );
		}
		else
		{
			$next_time = nv_date( "l, d/m/Y H:i", $row['start_time'] + ceil( ( NV_CURRENTTIME - $row['start_time'] ) / $interval ) * $interval );
		}
	}
	$contents[$row['id']]['detail'][$lang_module['next_time']] = $next_time;
}
$contents = call_user_func( "nv_main_cron", $contents );
include ( NV_ROOTDIR . "/includes/header.php" );
echo nv_admin_theme( $contents );
include ( NV_ROOTDIR . "/includes/footer.php" );

?>